export default {
    namespaced: true,
    actions: {
        updateSearch(context,value){
            let repeat = false
            context.state.searchHistory.forEach(item=>{
                if(item==value) repeat = true
            })
            context.commit('updateSearchWord',value);
            if(!repeat){
                context.commit('updateSearchHistory',value);
            }
        },
        clearHistory(context){
            context.state.searchHistory = [];
        }
    },
    mutations: {
        updateSearchWord(state,value){
            state.searchWord = value;
        },
        updateSearchHistory(state,value){
            state.searchHistory.unshift(value);
        }
    },
    state: {
        searchWord:'',
        searchHistory:[]
    }
}